# 创建时间：2025/5/2 星期五 15:08
# 创建人：李德才

class Person1(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def say_hello(self):
        print("Hello, my name is " + self.name + " and I am " + str(self.age) + " years old.")

    def __str__(self):  # 重写__str__方法,这个方法其实是object的方法
        return "Person1(name=" + self.name + ", age=" + str(self.age) + ")"


class Person2(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def say_hello(self):
        print("Hello, my name is " + self.name + " and I am " + str(self.age) + " years old.")


print(Person1("张三", 18))

""" 因为person2没有重写__str__方法,所以会调用object的__str__方法, """
print(Person2("张三", 18))
